# -*- coding: utf-8 -*-
"""
Created on Sat Jun  9 12:43:20 2012

@author: nzhao
"""

import numpy as np
from traits.api import Enum, Float, Str, Instance, Int

import phy.general.Constant as co
from phy.spin.AbstractSpinSystem import AbstractSpinSystem
from math_qm.CoordianteSystem import CoordinateSystem

class SingleSpin(AbstractSpinSystem):
    """
    doc for SingleSpin.
    """
    spin_element = Enum('NV', 'E', 'C13', 'N14', 'N15', 'H')
    spin_type    = Enum('Central', 'Bath')
    spin_mark    = Str('None')
    spin_relative_Gamma = Float
    dim = Int()
    
    axes = Instance(CoordinateSystem, () )
    
    x = Float(0.0)
    y = Float(0.0)
    z = Float(0.0)

    dist  = Float
    
    def __init__(self, element = 'NV', spin_type = 'Central', spin_mark='None', x = 0.0, y = 0.0, z = 0.0):
        self.spin_element = element
        self.spin_relative_Gamma = co.SpinDictionary[self.spin_element]['RelativeGyromagneticRatio']

        self.spin_type = spin_type
        self.spin_mark = spin_mark

        spin_value = co.SpinDictionary[self.spin_element]['SpinValue']
        self.dim   = int(2*spin_value + 1)

        self.x, self.y, self.z = x, y, z
        self.dist = (x**2 + y**2 + z**2)**0.5
        
    def postion(self):
        """
        return the position vector.
        """
        return np.array([self.x, self.y, self.z])
    
    def _spin_element_changed(self):
        self.spin_relative_Gamma = co.SpinDictionary[self.spin_element]['RelativeGyromagneticRatio']


if __name__ == '__main__':
    spin = SingleSpin()
    print spin.postion(), spin.spin_relative_Gamma